import _ from "lodash"
import { RouteConfig } from "vue-router"

const routes: Array<RouteConfig> = [
  {
    path: "/orders/reviews",
    name: "OrderReviewList",
    props: (route) => ({
      statuses: _.split(route.query.statuses as string, ","),
    }),
    component: () => import("../views/order").then(order => order.ReviewList),
    meta: { requiresAuth: true },
  },
  {
    path: "/orders",
    name: "OrderList",
    props: (route) => ({
      statuses: _.split(route.query.statuses as string, ","),
      reviewStatuses: _.split(route.query.review_statuses as string, ","),
    }),
    component: () => import("../views/order").then(order => order.List),
    meta: { requiresAuth: true },
  },
  {
    path: "/disputes",
    name: "OrderDisputeList",
    props: true,
    component: () => import("../views/order").then(order => order.DisputeList),
    meta: { requiresAuth: true },
  },
  {
    path: "/orders/:id",
    name: "OrderDetail",
    props: true,
    component: () => import("../views/order").then(order => order.Detail),
    meta: { requiresAuth: true },
  },
  {
    path: "/orders/:orderId/reviews/new",
    name: "OrderReviewNew",
    props: (route) => ({
      orderId: route.params.orderId,
    }),
    component: () => import("../views/order").then(order => order.ReviewNew),
    meta: { requiresAuth: true },
  },
  {
    path: "/orders/:id/refunds",
    name: "RefundApplySelectList",
    props: (route) => ({
      orderId: route.params.id,
      kind: route.query.kind,
      itemIds: _.split(route.query.item_ids as string, ","),
    }),
    component: () => import("../views/order").then(order => order.RefundApplySelectList),
    meta: { requiresAuth: true },
  },
  {
    path: "/orders/:id/refunds/apply",
    name: "OrderRefundApplyList",
    props: (route) => ({
      kind: route.query.kind,
      orderId: route.params.id,
      itemIds: _.split(route.query.item_ids as string, ","),
    }),
    component: () => import("../views/order").then(order => order.RefundApplyList),
    meta: { requiresAuth: true },
  },
  {
    path: "/orders/:orderId/refunds/:id",
    name: "OrderRefundDetail",
    props: true,
    component: () => import("../views/order").then(order => order.RefundDetail),
    meta: { requiresAuth: true },
  },
  {
    path: "/orders/:id/shipments",
    name: "OrderShipmentList",
    props: true,
    component: () => import("../views/order").then(order => order.ShipmentList),
    meta: { requiresAuth: true },
  },
]

export default routes
